package com.dhy.takeaway.service;

import com.dhy.takeaway.dao.GoodDao;
import com.dhy.takeaway.entity.Good;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class GoodsService {
    @Autowired
    private GoodDao goodDao;

    public boolean goodAdd(Good good){
        good.setCreateTime(new Date());
        good.setUpdateTime(new Date());
        if(goodDao.insertGood(good)>0){
            return true;
        };
        return false;
    }
    public boolean goodEdit(Good good){
        good.setUpdateTime(new Date());
        if(goodDao.updateGood(good)>0){
            return true;
        }
        return false;
    }

    public List<Good> goodList(String userId){
        return goodDao.selectGoodList(userId);
    }
    public List<Good> soleOutList(String userId){
        return goodDao.selectSoleOutList(userId);
    }

    public boolean soldOut(String id){
        if (goodDao.soldOut(id) > 0) {
            return true;
        }
        return false;
    }

    public boolean putAway(String id){
        if (goodDao.putAway(id) > 0) {
            return true;
        }
        return false;
    }

    public List<Good> findHotSale(String userId){
        return goodDao.findHotSale(userId);
    }

    public List<Good> findMustGood(String userId){
        return goodDao.findMustGood((userId));
    }
}
